package com.yc.web.controllers;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/i18n")
public class HelloController {

    @Value("${server.port}")
    private int port;

    private String language;

    @PostConstruct
    public void initLanguage() {
        switch (port) {
            case 8081 -> language = "zh";
            case 8082 -> language = "en";
            case 8083 -> language = "jp";
            default -> language = "en"; // 默认英文
        }
    }

    @GetMapping("/hello")
    public String hello() {
        return switch (language) {
            case "zh" -> "你好，世界";
            case "jp" -> "こんにちは、世界";
            default -> "Hello, World";
        };
    }
}
